import { isLogin, toLogin, getUserInfo, setUserInfo } from '../../utils/auth'
import area from '../../utils/area';
import { checkPhone } from "../../utils/validate";
import ValidateForm from "../../utils/validateForm";
import { showModel, showNotify, showToast, showDialog } from '../../utils/index'
import http from '../../utils/http'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: null,

        name: null,
        phone: null
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        // 用户登录信息
        this.setData({ userInfo: getUserInfo() });
    },

    /**
     * 提交申请
     */
    async handleApply() {
        let { name, phone, userInfo } = this.data

        if(!checkPhone(phone)) {
            return showToast({title: "手机号不正确"})
        }
        if(!name) {
            return showToast({title: "姓名不能为空"})
        }

        let form = {memberId: userInfo.id, name, phone}

        let res = await http.post('/api/mall/umsmemberdistributionapply/save', form)

        if(res.status) {
            wx.showModal({
                title: '提示',
                content: '提交成功，客服将与您联系！',
                showCancel: false,
                success(res) {
                    if (res.confirm) {
                        wx.navigateBack({ delta: 1 });
                    }
                }
            })
        } else {
            showToast({title: res.msg})
        }
    },

})